package c926.xiaoduyun.xiaodu.plugin.other;


import com.alibaba.fastjson.JSONObject;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.form.control.Button;
import kd.bos.form.control.Control;
import kd.bos.form.events.CustomEventArgs;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.servicehelper.operation.SaveServiceHelper;



public class MyComponentPlugin extends AbstractFormPlugin  {



    @Override
    public void customEvent(CustomEventArgs e) {
        String eventName = e.getEventName();
        if (eventName.equals("onCustomEvent")){
            String imageHtml = e.getEventArgs();
            DynamicObject dataEntity = this.getModel().getDataEntity(true);
            String text = dataEntity.getString("c926_largetextfield_tag");
            String signStatus = dataEntity.getString("c926_signstatus");
            if ("".equals(text) || null == text) {
                this.getView().showTipNotification("请先填写内容！");
                return;
            }
            if (!text.contains("盖章")) {
                this.getView().showTipNotification("内容中不包含签章关键字！");
                return;
            }
            if ("B".equals(signStatus)) {
                this.getView().showTipNotification("请勿重复签章！");
                return;
            }
            String updatedText = text.replace("盖章", "盖章" + imageHtml);
            this.getModel().setValue("c926_largetextfield_tag", updatedText);
            dataEntity.set("c926_largetextfield_tag", updatedText);
            dataEntity.set("c926_signstatus", "B");
            SaveServiceHelper.update(dataEntity);
            this.getView().showSuccessNotification("操作成功！");
            this.getView().updateView();
        }

    }


}